package org.example.servlet;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * 为退出建立servlet目的是销毁session
 */
public class OutServlet extends HttpServlet {
	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		
		//设置请求编码格式
		req.setCharacterEncoding("utf-8");
		//设置响应编码格式
		resp.setContentType("text/html; charset=utf-8");

		//获取请求信息
		//处理请求信息
		//获取session、销毁session
		HttpSession hs = req.getSession();
		hs.invalidate();

		//相应处理结果
		//直接响应
		//请求转发
		//重定向
		resp.sendRedirect("/login.jsp");
	}
}
